/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2491.java
 * @Author : WangRuoyu
 * @Date 2022/12/17 18:54
 */

package leetcode;

import java.util.Arrays;

public class Q2491 {
    public long dividePlayers(int[] skill) {
        long res = 0;
        Arrays.sort(skill);
        int n = skill.length;
        int tmp = skill[0] + skill[n - 1];
        for (int i = 0; i <= (n / 2) - 1; i++) {
            if (tmp != (skill[i] + skill[n - 1 - i])) {
                return -1;
            } else {
                res += (skill[i] * skill[n - 1 - i]);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Q2491 sl = new Q2491();
        int[] skill = {3, 2, 5, 1, 3, 4};
        System.out.println(sl.dividePlayers(skill));
    }
}
